import { createAsyncThunk } from '@reduxjs/toolkit';
import axios, { AxiosError } from 'axios';
import { API } from '../../helpers/API';
import { IFormData } from './auth.types';



export const fetchRegistration = createAsyncThunk<unknown, IFormData>(
	'registration/fetchRegistration',
	async (formData) => {
		try {
			const { data } = await axios.post(`${API}/register`, {
				formData
			});
			return data;
		} catch (error) {
			if (error instanceof AxiosError) {
				throw new Error(error.response?.data.message);
			}
		}
	}
);